from config_default import configs


def merge(defaults, overried):
    r = {}
    for k, v in defaults.items():
        if k in overried:
            if isinstance(v, dict):
                r[k] = merge(defaults[k], overried[k])
            else:
                r[k] = overried[k]
        else:
            r[k] = v
    return r


try:
    from config_override import configs as con
    configs = merge(configs, con)
except ImportError:
    pass


class Dict(dict):

    def __init__(self, names=(), values=(), **kw):
        super().__init__(**kw)
        for k, v in zip(names, values):
            self[k] = v

    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError:
            raise AttributeError(
                r"'Dict' object has no attribute like '%s'" % key)

    def __setattr__(self, key, value):
        self[key] = value


def toDict(configs):
    D = Dict()
    for k, v in configs.items():
        D[k] = toDict(v) if isinstance(v, dict) else v
    return D


configs = toDict(configs)
